package com.pan.controller.ListenerController;

import com.pan.aop.BusinessType;
import com.pan.aop.MyLog;
import com.pan.controller.tools.Methods;
import com.pan.controller.tools.R1;
import com.pan.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/listeners")
@Tag(name = "ListnerController",description = "监听器，显示在线人数")
public class ListnerController {
    @Autowired
    private IUserService userService;

    Methods methods = new Methods();

    @Operation(summary = "监控在线人数 ")
    @GetMapping
    @MyLog(title = "操作员监控在线人数",optParam = "无",businessType = BusinessType.OTHER)
    public R1 getTotalUser(HttpServletRequest request){
        //检查用户权限
        if (methods.isYanfa(request,userService)){
            Integer count = (Integer) request.getSession().getServletContext().getAttribute("count");
            System.out.println();
            return new R1(true,"当前在线人数为 "+count);
        }
        return new R1(false,"权限不足！");
    }
}
